<?php TPL::output('m/header_meta.tpl.htm'); ?>

<body style="background:#FFF;">

<article class="l-logo"><img src="<?php echo G_STATIC_URL; ?>/mobile/img/login-logo.png"></article>


<article class="regtab">
	<ul>
		<?php if( ($this->other_valid && $this->other_valid['type'] == 'email') || $this->type == 'email'){ ?>
    	<li class="emilreg <?php if($this->type == 'email'){ ?> cur <?php }?>" onclick="window.location.href='m/register/type-email'">邮箱注册</li>
    	<?php }?>
    	<?php if(get_hook_info('mobile_regist')['state'] == 1 && ($this->other_valid && $this->other_valid['type'] == 'mobile') || $this->type == 'mobile' ){ ?>
        <li class="phonereg <?php if($this->type == 'mobile'){ ?> cur <?php }?> " onclick="window.location.href='m/register/type-mobile'">手机注册</li>
        <?php }?>
    </ul>
</article>

<article class="frombox" id="emilbox">
<form id="register_form" method="post" action="account/ajax/register_process/type-<?php echo $this->type?>">
	<input type="hidden" name="agreement_chk" value="agree" />

	<?php if ($this->icode) { ?>
		<input type="hidden" name="icode" id="icode" value="<?php echo $this->icode; ?>" />
	<?php } ?>
	
	<?php if ($this->return_url) { ?>
		<input type="hidden" name="return_url" value="<?php echo $this->return_url; ?>" />
	<?php } ?>
    <ul>
        <li><i style="top: 18px;"><img src="<?php echo G_STATIC_URL; ?>/mobile/images/name.png"></i><input name="user_name" type="text" class="name" placeholder="请输入用户名" style="height: 36px;" value="<?php echo htmlspecialchars($_GET['user_name']); ?>"></li>
    <?php if($this->type == 'mobile'){?>
        <li><i><img src="<?php echo G_STATIC_URL; ?>/mobile/images/phonereg.png"></i><input id="phone" name="mobile" type="text" class="name" placeholder="请输入手机号码" value="<?php echo htmlspecialchars($_GET['mobile']); ?>"></li>
        <li style="height: 45px;">
            <div class="embed-captcha" style="margin-top: 5px;"></div>
            <p class="wait">正在加载验证码......</p>
        </li>
        <li>
            <i><img src="<?php echo G_STATIC_URL; ?>/mobile/images/pcode.png"></i>
            <input name="smscode" type="text"  placeholder="请输入短信验证码">
            <a href="javascript:;" class="hrefcode" id="Smsbtn">获取验证码</a>
        </li>
        <li>
            <i><img src="<?php echo G_STATIC_URL; ?>/mobile/images/pass.png"></i>
            <input type="password" class="aapass" placeholder="请输入密码">
            <input id="aw-login-user-repassword" type="hidden" name="password" />
        </li>
    <?php } else {?>
         <li><i><img src="<?php echo G_STATIC_URL; ?>/mobile/images/emial.png"></i><input name="email" type="text" class="name" placeholder="请输入邮箱" value="<?php echo htmlspecialchars(urldecode($_GET['email'])); ?>"></li>
        <li>
            <i><img src="<?php echo G_STATIC_URL; ?>/mobile/images/pass.png"></i>
            <input type="password" class="aapass" placeholder="请输入密码">
            <input id="aw-login-user-repassword" type="hidden" name="password" />
        </li>
        <?php if (get_setting('register_seccode') == 'Y') { ?>
        <li style="height: 45px;">
            <div class="embed-captcha" style="margin-top: 5px;"></div>
            <p class="wait">正在加载验证码......</p>
        </li>
        <?php } ?>
    <?php } ?>
    </ul>
    <span class="loginbut"><input type="button" id="zhuce" <?php if ((get_setting('register_seccode') == 'N' and $this->type=='email') || $this->type=='mobile') { ?> onclick=" $('#aw-login-user-repassword').val(encrypt_pass($('.aapass').val()));AWS.ajax_post($('#register_form'), AWS.ajax_processer, 'error_message'); return false;" <?php } ?> value="注 册"></span>
   
    <span class="otherinfo clearfix"> 
        <a href="m/login/" class="clickreg"><img src="<?php echo G_STATIC_URL; ?>/mobile/images/reg.png">已有账号，点击登录</a>
    </span>
</form> 
</article>

<script type="text/javascript">
$(".regtab ul li").click(function(){
	$(this).addClass("cur").siblings().removeClass("cur");
});	

$(".regtab ul li.emilreg").click(function(){
	$(this).closest(".regtab").siblings("#emilbox").show();
	$(this).closest(".regtab").siblings("#phonebox").hide();
});	

$(".regtab ul li.phonereg").click(function(){
	$(this).closest(".regtab").siblings("#emilbox").hide();
	$(this).closest(".regtab").siblings("#phonebox").show();
});
/*仿刷新：检测是否存在cookie*/
if($.cookie("captcha")){
    var count = $.cookie("captcha");
    var btn = $('#Smsbtn');
    $('#Smsbtn').prop('disabled', true);
    btn.text(count+'秒');
    var resend = setInterval(function(){
        count--;
        if (count > 0){
            // btn.text(count+'秒后可重新获取')
            btn.text(count+'秒');
            $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
        }else {
            $('#Smsbtn').prop('disabled', false);
            clearInterval(resend);
            btn.text("获取验证码")
        }
    }, 1000);
}

var handlerEmbed = function (captchaObj) {
    $("#Smsbtn").click(function (e) {
        var phonereg = /^1[3456789]\d{9}$/;
        var mobile = $('input[name="mobile"]').val();

        if(mobile=='' ){
            alert("请输入手机号");
            return false;
        }
        if(!phonereg.test(mobile)){
            alert("手机号格式不正确");
            return false;
        }
        if($('#Smsbtn').text()!="获取验证码"){
            return false;
        }

        var validate = captchaObj.getValidate();
        if (!validate) {
            alert("请先完成验证");
            return false;
        } else{
            $.post(G_BASE_URL + '/account/ajax/check_mobile/',{
                mobile:mobile,
                type:'regist',
            }, function (result)
            {
                if (result.errno == -1)
                {
                    alert(result.err);
                    captchaObj.reset();
                    return false;
                }else{
                    $.ajax({
                        url: G_BASE_URL + '/tools/sendSms/',
                        type: "post",
                        dataType: "json",
                        data: {
                            mobile: mobile,
                            challenge: '',
                            geetest_challenge: validate.geetest_challenge,
                            geetest_validate: validate.geetest_validate,
                            geetest_seccode: validate.geetest_seccode,
                            client_type: 'h5',
                            genre: '1'
                        },
                        success: function (result) {
                            if(result.errno == -1)
                            {
                                alert(result.err);
                                captchaObj.reset(); // 调用该接口进行重置 
                                return false;
                            }else
                            {
                                alert(result.err);
                                var count = 60;
                                var inl = setInterval(function () {
                                    $('#Smsbtn').prop('disabled', true);
                                    count -= 1;
                                    var text = count + ' 秒';
                                    $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
                                    $('#Smsbtn').text(text);
                                    if (count <= 0) {
                                        clearInterval(inl);
                                        $('#Smsbtn').prop('disabled', false);
                                        $('#Smsbtn').text('获取验证码');
                                    }
                                }, 1000);
                                return true;
                            }

                        }
                    });
                }
            }, 'json');
        }
    });
<?php if (get_setting('register_seccode') == 'Y' and $this->type=='email') { ?>
    $('#zhuce').click(function(){
        var validate = captchaObj.getValidate();
        if (!validate) {
            alert("请先完成验证");
            return false;
        } else{
            $('#aw-login-user-repassword').val(encrypt_pass($('.pass').val()));
            AWS.ajax_post($('#register_form'), AWS.ajax_processer, 'error_message'); 
            captchaObj.reset(); // 调用该接口进行重置 
            return false;
        }
    });
<?php } ?>
<?php if ((get_setting('register_seccode') == 'Y' and $this->type=='email') || $this->type=='mobile') { ?>
    // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
    captchaObj.appendTo(".embed-captcha");
    captchaObj.onReady(function () {
        $(".wait").css('display','none');
    });
<?php } ?>
};

$.ajax({
    // 获取id，challenge，success（是否启用failback）
    url: G_BASE_URL+ "/account/slide_captcha/?t=" + (new Date()).getTime()+"&client_type='web'", // 加随机数防止缓存
    type: "get",
    dataType: "json",
    success: function (data) {
        var dataObj = eval('(' + data.rsm + ')');
        // 使用initGeetest接口
        // 参数1：配置参数
        // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
        initGeetest({
            gt: dataObj.gt,
            challenge: dataObj.challenge,
            new_captcha: dataObj.new_captcha,
            offline: !dataObj.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
            product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
            width: '100%' // 设置按钮宽度, 与父元素宽度一致
        }, handlerEmbed);
    }
});
</script>
<?php TPL::output('m/footer.tpl.htm'); ?>